#!/usr/bin/python
# -*- coding: UTF-8 -*-
'''
行业排名统计
'''
import pandas as pd
import operator
dir = "C:\\Users\\Administrator\\Desktop"
from pyecharts.charts import Bar

industry=[]# 行业
concepts_industry=[] #概念
without=["转融券标的","融资融券","深股通","沪股通"]



def result_concepts_industry(data,title):
    all=[]
    final_result={}
    results = data["所属概念"].values
    for result in results:
       for r in result.split(";"):
           if r in without:
               continue
           if r in final_result:
               final_result[r]=final_result.get(r)+1
           else:
               final_result[r]=1
    sort_result=sorted(final_result.items(),key=operator.itemgetter(1))
    for key,value in sort_result:
        print(key,":",value)

    df2=pd.DataFrame(sort_result)
    df2=df2[df2[1]>1]
    print(df2)
    # bar = pc.Bar(title)
    # bar.add("", df2[0], df2[1], mark_point=["max"], is_convert=True)
    # bar.render(title+".html")



def result_industry(data,title):
    all=[]
    final_result={}
    results = data["所属同花顺行业"].values
    for result in results:
       for r in result.split("-"):
           if r in without:
               continue
           if r in final_result:
               final_result[r]=final_result.get(r)+1
           else:
               final_result[r]=1
    sort_result=sorted(final_result.items(),key=operator.itemgetter(1))
    for key,value in sort_result:
        print(key,":",value)
    df2=pd.DataFrame(sort_result)
    df2.to_excel("week.xlsx")
    # df2=df2[df2[1]>5]

    # bar = Bar()
    # print(df2[0].to_list())
    # bar.add_xaxis(df2[0].to_list())
    # bar.add_yaxis("最近一周新高",df2[1].to_list())
    #
    # bar.render()



def get_stock_code():
    path = dir + "\\stock.csv"
    data = pd.read_csv(path, encoding="GB2312")
    print("path",path)
    # result_concepts_industry(data)
    result_industry(data,"最近一周股票创历史新高所属行业")
    # result_concepts_industry(data,"最近一周股票创历史新高所属概念行业")


def test():
    path = dir + "\\industry.csv"
    data = pd.read_csv(path, encoding="GB2312")





get_stock_code()
